﻿/**
 * 上传面板。
 */
Ext.define('Happy.fileupload.Window', {
    extend: 'Ext.window.Window',
    alias: 'widget.happy-fileupload-window',
    requires: ['Happy.fileupload.Panel'],

    /**
     * @cfg 重写 ExtJs。
     */
    buttonAlign: 'center',
    /**
     * @cfg。
     */
    uploadButtonText: '上传',
    /**
     * @cfg。
     */
    closeButtonText: '关闭',
    /**
     * @cfg {Object} fileUploadFormConfig。
     */

    /**
     * 重写 ExtJs。
     * 
     * @protected
     */
    initComponent: function () {
        var me = this;

        me.configItems();
        me.configButtons();

        me.callParent(arguments);
    },

    /**
     * @protected
     */
    configItems: function () {
        var me = this;

        Ext.apply(me, {
            layout: 'fit',
            items: Ext.applyIf({
                xtype: 'happy-fileupload-panel'
            }, me.fileUploadFormConfig || {})
        });
    },

    /**
     * @protected
     */
    configButtons: function () {
        var me = this;

        Ext.apply(me, {
            buttons: [
                {
                    text: me.uploadButtonText,
                    handler: Ext.bind(me.on_Happy_fileupload_Window_UploadButton_Click_Handler, me)
                },
                {
                    text: me.closeButtonText,
                    handler: Ext.bind(me.close, me)
                }
            ]
        });
    },

    /**
     * @private
     */
    on_Happy_fileupload_Window_UploadButton_Click_Handler: function () {
        var me = this;

        me.down('happy-fileupload-panel').upload();
    },


    /**
     * 重写 ExtJs。
     * 
     * @protected
     */
    onRender: function () {
        var me = this;

        me.callParent(arguments);

        this.relayEvents(me.down('happy-fileupload-panel'), ['fileuploaded']);
    }
});